#pragma once
#include <ctemplate/template.h>
#include "comm/util.hpp"
#include "oj_model2.hpp"
#include <ctemplate/template.h>
namespace ns_view
{

    using namespace std;
    using namespace ns_util;
    using namespace ns_model;

    const std::string template_path = "./template_html/";
    class View
    {
    public:
        View() {}
        ~View() {}
        void allExpandHtml(const vector<Question> questions, string *html)
        {
            // 题目的编号, 标题, 难度
            // *推荐选择表格来实现这样的功能
            // &1.形成路径 
            string src_html = template_path + "all_question.html";
            // =2. 形成字典
            ctemplate::TemplateDictionary root("all_question");
            for (const auto& q : questions)
            {
                auto sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q.number);
                sub->SetValue("title", q.title);
                sub->SetValue("star", q.star);
            }

            // &3. 获取被渲染的html
            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);

            // &4. 开始完成渲染功能
            tpl->Expand(html, &root);
        }
        void oneExpandHtml(const Question &q, string *html)
        {
            // &1. 形成路径
            string src_html = template_path + "one_question.html";
            // &2. 行程数据字典
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", q.number);
            root.SetValue("title", q.title);
            root.SetValue("star", q.star);
            root.SetValue("desc", q.desc);
            root.SetValue("pre_code", q.header);
            // &3. 获取被渲染的网页
            auto tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            // &4. 开始渲染
            tpl->Expand(html, &root);
        }

    private:
    };
}